﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AesonBaseFramework.EntityFramework.Validation.Attribute
{
    public class IsEmail : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            try
            {
                if (value != null)
                {
                    if (value.ToString().Contains("@") && value.ToString().Contains("."))
                    {
                        return ValidationResult.Success;
                    }
                    else
                    {
                        return new ValidationResult("Email not valide");
                    }
                }
                else
                {
                    return new ValidationResult("Email value not set");
                }

            }
            catch (Exception exc)
            {
                return new ValidationResult("Exception validating Email Adress : " + exc.Message);
            }



        }
    }
}
